
****INDIVIDUAL FORECASTS 
eststo clear

use "$jfqa_rep/21_DJIA_convexity_40.dta", clear

qui{
merge 1:m year month day using "$jfqa_rep/Shiller_Individual_Ests.dta"
keep if _merge==3
drop _merge

sort year month day

gen monthyear=ym(year, month)

drop if abs(dow_1m)>=.5

gen wret_1=(1+ret_5)*(1+ret_1)*(1+ret_2)*(1+ret_3)*(1+ret_4)-1
gen wret_2=(1+ret_10)*(1+ret_6)*(1+ret_7)*(1+ret_8)*(1+ret_9)-1
gen wret_3=(1+ret_15)*(1+ret_11)*(1+ret_12)*(1+ret_13)*(1+ret_14)-1
gen wret_4=(1+ret_20)*(1+ret_16)*(1+ret_17)*(1+ret_18)*(1+ret_19)-1
gen wret_5=(1+ret_25)*(1+ret_21)*(1+ret_22)*(1+ret_23)*(1+ret_24)-1
gen wret_6=(1+ret_30)*(1+ret_26)*(1+ret_27)*(1+ret_28)*(1+ret_29)-1
gen wret_7=(1+ret_35)*(1+ret_31)*(1+ret_32)*(1+ret_33)*(1+ret_34)-1
gen wret_8=(1+ret_40)*(1+ret_36)*(1+ret_37)*(1+ret_38)*(1+ret_39)-1

gen futwret_1=(1+futret_1)*(1+futret_2)*(1+futret_3)*(1+futret_4)*(1+futret_5)-1
gen futwret_2=(1+futret_6)*(1+futret_7)*(1+futret_8)*(1+futret_9)*(1+futret_10)-1
gen futwret_3=(1+futret_11)*(1+futret_12)*(1+futret_13)*(1+futret_14)*(1+futret_15)-1
gen futwret_4=(1+futret_16)*(1+futret_17)*(1+futret_18)*(1+futret_19)*(1+futret_20)-1
gen futmret_1=(1+futwret_1)*(1+futwret_2)*(1+futwret_3)*(1+futwret_4)*(1+futret_21)-1

collapse lag_convexity wret* dow_1m fut*, by(year month day monthyear)

gen obs=_n

gen fit_expect_8=.
tsset obs

*8 lags
forval i=500/2538 {	
nl (dow_1m = {b0} + ///
	{b1}*(({b2}*wret_1)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8) + ///
		({b2}^2*wret_2)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8) + ///
		({b2}^3*wret_3)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8) + ///
		({b2}^4*wret_4)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8) + ///
		({b2}^5*wret_5)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8) + ///
		({b2}^6*wret_6)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8) + ///
		({b2}^7*wret_7)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8) + ///
		({b2}^8*wret_8)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8))) if obs<(`i'+1), ///
		initial(b0 0 b1 1 b2 0.5) nolog vce(cluster monthyear)

gen fit_expect= _b[/b0] + ///
	_b[/b1]*((_b[/b2]*wret_1)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8) + ///
		(_b[/b2]^2*wret_2)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8) + ///
		(_b[/b2]^3*wret_3)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8) + ///
		(_b[/b2]^4*wret_4)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8) + ///
		(_b[/b2]^5*wret_5)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8) + ///
		(_b[/b2]^6*wret_6)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8) + ///
		(_b[/b2]^7*wret_7)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8) + ///
		(_b[/b2]^8*wret_8)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8))  if obs<(`i'+1)
	
replace fit_expect_8=fit_expect if obs==`i'
drop fit_expect
}

drop if missing(fit_expect_8)

replace fit_expect_8=fit_expect_8*100
replace futmret_1=futmret_1*100
replace dow_1m=dow_1m*100

gen res_expect_8=dow_1m-fit_expect_8
egen res_expect_8_std=std(res_expect_8)
egen fit_expect_8_std=std(fit_expect_8)
egen dow_1m_std=std(dow_1m)
egen convex_std=std(lag_convexity)

}

****TABLE 10****
*coefficients and t-stats
newey futmret_1 dow_1m_std, lag(8)
newey futmret_1 fit_expect_8_std, lag(8)
newey futmret_1 res_expect_8_std, lag(8)

*R-squared
reg futmret_1 dow_1m_std
reg futmret_1 fit_expect_8_std
reg futmret_1 res_expect_8_std

****TABLE 11****
*coefficients and t-stats
newey dow_1m convex_std, lag(8)
newey fit_expect_8 convex_std, lag(8)
newey res_expect_8 convex_std, lag(8)

*R-squared
reg dow_1m convex_std
reg fit_expect_8 convex_std
reg res_expect_8 convex_std


****INSTITUTIONAL FORECASTS
use "$jfqa_rep/21_DJIA_convexity_40.dta", clear

qui{
merge 1:m year month day using "$jfqa_rep/Shiller_Inst_Ests.dta"
keep if _merge==3
drop _merge

sort year month day

gen monthyear=ym(year, month)

drop if year<1993

drop if abs(dow_1m)>=.5

gen wret_1=(1+ret_5)*(1+ret_1)*(1+ret_2)*(1+ret_3)*(1+ret_4)-1
gen wret_2=(1+ret_10)*(1+ret_6)*(1+ret_7)*(1+ret_8)*(1+ret_9)-1
gen wret_3=(1+ret_15)*(1+ret_11)*(1+ret_12)*(1+ret_13)*(1+ret_14)-1
gen wret_4=(1+ret_20)*(1+ret_16)*(1+ret_17)*(1+ret_18)*(1+ret_19)-1
gen wret_5=(1+ret_25)*(1+ret_21)*(1+ret_22)*(1+ret_23)*(1+ret_24)-1
gen wret_6=(1+ret_30)*(1+ret_26)*(1+ret_27)*(1+ret_28)*(1+ret_29)-1
gen wret_7=(1+ret_35)*(1+ret_31)*(1+ret_32)*(1+ret_33)*(1+ret_34)-1
gen wret_8=(1+ret_40)*(1+ret_36)*(1+ret_37)*(1+ret_38)*(1+ret_39)-1

gen futwret_1=(1+futret_1)*(1+futret_2)*(1+futret_3)*(1+futret_4)*(1+futret_5)-1
gen futwret_2=(1+futret_6)*(1+futret_7)*(1+futret_8)*(1+futret_9)*(1+futret_10)-1
gen futwret_3=(1+futret_11)*(1+futret_12)*(1+futret_13)*(1+futret_14)*(1+futret_15)-1
gen futwret_4=(1+futret_16)*(1+futret_17)*(1+futret_18)*(1+futret_19)*(1+futret_20)-1
gen futmret_1=(1+futwret_1)*(1+futwret_2)*(1+futwret_3)*(1+futwret_4)*(1+futret_21)-1

collapse lag_convexity wret* dow_1m fut*, by(year month day monthyear)

gen obs=_n

gen fit_expect_8=.
tsset obs

*8 lags
forval i=500/2529 {	
nl (dow_1m = {b0} + ///
	{b1}*(({b2}*wret_1)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8) + ///
		({b2}^2*wret_2)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8) + ///
		({b2}^3*wret_3)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8) + ///
		({b2}^4*wret_4)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8) + ///
		({b2}^5*wret_5)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8) + ///
		({b2}^6*wret_6)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8) + ///
		({b2}^7*wret_7)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8) + ///
		({b2}^8*wret_8)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8))) if obs<(`i'+1), ///
		initial(b0 0 b1 1 b2 0.5) nolog vce(cluster monthyear)

gen fit_expect= _b[/b0] + ///
	_b[/b1]*((_b[/b2]*wret_1)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8) + ///
		(_b[/b2]^2*wret_2)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8) + ///
		(_b[/b2]^3*wret_3)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8) + ///
		(_b[/b2]^4*wret_4)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8) + ///
		(_b[/b2]^5*wret_5)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8) + ///
		(_b[/b2]^6*wret_6)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8) + ///
		(_b[/b2]^7*wret_7)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8) + ///
		(_b[/b2]^8*wret_8)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8))  if obs<(`i'+1)
	
replace fit_expect_8=fit_expect if obs==`i'
drop fit_expect
}

drop if missing(fit_expect_8)

replace fit_expect_8=fit_expect_8*100
replace futmret_1=futmret_1*100
replace dow_1m=dow_1m*100

gen res_expect_8=dow_1m-fit_expect_8
egen res_expect_8_std=std(res_expect_8)
egen fit_expect_8_std=std(fit_expect_8)
egen dow_1m_std=std(dow_1m)
egen convex_std=std(lag_convexity)

}

****TABLE 10****
*coefficients and t-stats
newey futmret_1 dow_1m_std, lag(8)
newey futmret_1 fit_expect_8_std, lag(8)
newey futmret_1 res_expect_8_std, lag(8)

*R-squared
reg futmret_1 dow_1m_std
reg futmret_1 fit_expect_8_std
reg futmret_1 res_expect_8_std

****TABLE 11****
*coefficients and t-stats
newey dow_1m convex_std, lag(8)
newey fit_expect_8 convex_std, lag(8)
newey res_expect_8 convex_std, lag(8)

*R-squared
reg dow_1m convex_std
reg fit_expect_8 convex_std
reg res_expect_8 convex_std


****ALL FORECASTS
eststo clear
use "$jfqa_rep/21_DJIA_convexity_40.dta", clear

qui{
merge 1:m year month day using "$jfqa_rep/Shiller_Inst_Ests.dta"
keep if _merge==3
drop _merge

preserve
tempfile copy

use "$jfqa_rep/21_DJIA_convexity_40.dta", clear

merge 1:m year month day using "$jfqa_rep/Shiller_Individual_Ests.dta"
keep if _merge==3
drop _merge

save `copy', replace

restore
append using `copy'

sort year month day

gen monthyear=ym(year, month)

drop if year<1993

drop if abs(dow_1m)>=.5

gen wret_1=(1+ret_5)*(1+ret_1)*(1+ret_2)*(1+ret_3)*(1+ret_4)-1
gen wret_2=(1+ret_10)*(1+ret_6)*(1+ret_7)*(1+ret_8)*(1+ret_9)-1
gen wret_3=(1+ret_15)*(1+ret_11)*(1+ret_12)*(1+ret_13)*(1+ret_14)-1
gen wret_4=(1+ret_20)*(1+ret_16)*(1+ret_17)*(1+ret_18)*(1+ret_19)-1
gen wret_5=(1+ret_25)*(1+ret_21)*(1+ret_22)*(1+ret_23)*(1+ret_24)-1
gen wret_6=(1+ret_30)*(1+ret_26)*(1+ret_27)*(1+ret_28)*(1+ret_29)-1
gen wret_7=(1+ret_35)*(1+ret_31)*(1+ret_32)*(1+ret_33)*(1+ret_34)-1
gen wret_8=(1+ret_40)*(1+ret_36)*(1+ret_37)*(1+ret_38)*(1+ret_39)-1

gen futwret_1=(1+futret_1)*(1+futret_2)*(1+futret_3)*(1+futret_4)*(1+futret_5)-1
gen futwret_2=(1+futret_6)*(1+futret_7)*(1+futret_8)*(1+futret_9)*(1+futret_10)-1
gen futwret_3=(1+futret_11)*(1+futret_12)*(1+futret_13)*(1+futret_14)*(1+futret_15)-1
gen futwret_4=(1+futret_16)*(1+futret_17)*(1+futret_18)*(1+futret_19)*(1+futret_20)-1
gen futmret_1=(1+futwret_1)*(1+futwret_2)*(1+futwret_3)*(1+futwret_4)*(1+futret_21)-1

collapse lag_convexity wret* dow_1m fut*, by(year month day monthyear)

gen obs=_n

gen fit_expect_8=.
tsset obs

*8 lags
forval i=700/3575 {
nl (dow_1m = {b0} + ///
	{b1}*(({b2}*wret_1)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8) + ///
		({b2}^2*wret_2)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8) + ///
		({b2}^3*wret_3)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8) + ///
		({b2}^4*wret_4)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8) + ///
		({b2}^5*wret_5)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8) + ///
		({b2}^6*wret_6)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8) + ///
		({b2}^7*wret_7)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8) + ///
		({b2}^8*wret_8)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8))) if obs<(`i'+1), ///
		initial(b0 0 b1 1 b2 0.5) nolog vce(cluster monthyear)

gen fit_expect= _b[/b0] + ///
	_b[/b1]*((_b[/b2]*wret_1)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8) + ///
		(_b[/b2]^2*wret_2)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8) + ///
		(_b[/b2]^3*wret_3)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8) + ///
		(_b[/b2]^4*wret_4)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8) + ///
		(_b[/b2]^5*wret_5)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8) + ///
		(_b[/b2]^6*wret_6)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8) + ///
		(_b[/b2]^7*wret_7)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8) + ///
		(_b[/b2]^8*wret_8)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8))  if obs<(`i'+1)
	
replace fit_expect_8=fit_expect if obs==`i'
drop fit_expect
}

drop if missing(fit_expect_8)

replace fit_expect_8=fit_expect_8*100
replace futmret_1=futmret_1*100
replace dow_1m=dow_1m*100

gen res_expect_8=dow_1m-fit_expect_8
egen res_expect_8_std=std(res_expect_8)
egen fit_expect_8_std=std(fit_expect_8)
egen dow_1m_std=std(dow_1m)
egen convex_std=std(lag_convexity)

}

****TABLE 10****
*coefficients and t-stats
newey futmret_1 dow_1m_std, lag(8)
newey futmret_1 fit_expect_8_std, lag(8)
newey futmret_1 res_expect_8_std, lag(8)

*R-squared
reg futmret_1 dow_1m_std
reg futmret_1 fit_expect_8_std
reg futmret_1 res_expect_8_std

****TABLE 11****
*coefficients and t-stats
newey dow_1m convex_std, lag(8)
newey fit_expect_8 convex_std, lag(8)
newey res_expect_8 convex_std, lag(8)

*R-squared
reg dow_1m convex_std
reg fit_expect_8 convex_std
reg res_expect_8 convex_std

